/**
 * 
 */
package com.hs.app.dwr;

import java.io.File;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory;
import org.jfree.util.Log;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.hs.app.helper.DataImpObservable;
import com.hs.app.helper.DataImpObserver;
import com.hs.app.model.CdcBiblio;
import com.hs.app.service.IDataService;
import com.hs.auth.model.HsAccount;
import com.hs.core.db.DBMgr;
import com.hs.core.dwr.DwrHelper;
import com.hs.core.imp.ExcelImportUtil;
import com.hs.core.service.IService;
import com.hs.core.utils.TimeUtil;

/**
 * @author Administrator
 *
 */
public class CatagoryHelper extends DwrHelper{
	/**
	 * 新增或修改主题分类
	 * @param cid
	 * @param catagoryname
	 * @param catagoryengname
	 * @return
	 */
    public String saveCatagory(String cid,String catagoryname,String catagoryengname,String tagtype){
     	DBMgr dbo = this.getDbo(this.getHttpServletRequest()); 
     	String id = null;
     	String sql = "Insert into CDC_TAGS(ID, PID, TAGNAME, TAGNAMENG, IMPDATE, ISDELETE, TAGTYPE, ORDERNUM) values(?,?,?,?,?,1,?,?)";
     	if(StringUtils.isEmpty(cid)){
     		id = this.getSeqValue("SEQ_CDC_TAGS_ID");
        	dbo.update(sql, new Object[]{id,tagtype,catagoryname,catagoryengname,TimeUtil.getCurrentDate(),tagtype,id}); 
     	}else{
     		id = cid;
         	sql = "update CDC_TAGS set TAGNAME =?, TAGNAMENG =?,pid=? where id=?";
        	dbo.update(sql, new Object[]{catagoryname,catagoryengname,tagtype,id}); 

     	} 
 
    	return id;
    }
    
    /**
	 * 删除数据及已导入的数据
	 * @param fileId
	 * @return
	 */
    public String delCatagoryById(String fileId,String datatype){
    	DBMgr dbo = this.getDbo(this.getHttpServletRequest()); 
    	if(null == fileId || "null".equalsIgnoreCase(fileId)){
    		Log.debug("参数不完整");
    		return "";
    	}  
    	dbo.update("delete from CDC_tags where id=?", new Object[]{fileId});  
    	return "删除成功";
    }
 
	/**
	 * 获得session
	 * @return
	 */
	public HttpSession getHttpSession(){
		WebContext ctx = WebContextFactory.get();   
		return ctx.getSession();   
	}
	/**
	 * 
	 * @return
	 */
	public DBMgr getDbo(){
		DBMgr dbo = DBMgr.getDbUtilInst(getHttpSession().getServletContext());
		return dbo;
	} 
	public IService getServiceInst(String beanname){
	         WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getHttpSession().getServletContext());
//	         String[] names = wac.getBeanDefinitionNames();
//	         for(int i = 0;i<names.length;i++){
//	        	  System.out.println("bean:" + names[i]);
//	         }
	         return (IService)wac.getBean(beanname);
	}
}
